package com.lenovo.framework.util;

import android.app.Activity;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class WindowUtils {
    public static int getWindowWidth(WindowManager wm) {
        DisplayMetrics metric = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(metric);
        return metric.widthPixels;
    }

    public static int getStatusBarHeight1(Activity activity) {
        final Resources resources = activity.getResources();
        final int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            return resources.getDimensionPixelSize(resourceId);
        } else {
            return (int) Math.ceil(25 * resources.getDisplayMetrics().density);
        }
    }

    /**
     * 获得状态栏的高度
     *
     * @param context
     * @return
     */
    public static int getStatusBarHeight(Activity context) {
        int statusHeight = -1;
        try {
            Class<?> clazz = Class.forName("com.android.internal.R$dimen");
            Object object = clazz.newInstance();
            int height = Integer.parseInt(clazz.getField("status_bar_height")
                    .get(object).toString());
            statusHeight = context.getResources().getDimensionPixelSize(height);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return statusHeight;
    }

    public static int getWindowHeight(WindowManager wm) {
        DisplayMetrics metric = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(metric);
        return metric.heightPixels;
    }

    public static int getSuitSize(int oldWindowWidth, int nowWindowWidth, int suitSize) {
        return (int) ((nowWindowWidth * 1.0 / oldWindowWidth) * suitSize);
    }
}
